class HomeDeviceModel {
  String? type;
  bool? success;
  List<HomeDeviceModelData>? data;
  String? index;

  HomeDeviceModel({this.type, this.success, this.data, this.index});

  HomeDeviceModel.fromJson(Map json) {
    type = json['type'];
    success = json['success'];
    if (json['data'] != null) {
      data = <HomeDeviceModelData>[];
      json['data'].forEach((v) {
        data!.add(HomeDeviceModelData.fromJson(v));
      });
    }
    index = json['index'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = {};
    data['type'] = type;
    data['success'] = success;
    if (this.data != null) {
      data['data'] = this.data!.map((v) => v.toJson()).toList();
    }
    data['index'] = index;
    return data;
  }
}

class HomeDeviceModelData {
  String? type;
  String? name;
  List<HomeDeviceModelDevices>? devices;
  bool? selected;

  HomeDeviceModelData({this.type, this.name, this.devices, this.selected});

  HomeDeviceModelData.fromJson(Map json) {
    type = json['type'];
    name = json['name'];
    if (json['devices'] != null) {
      devices = <HomeDeviceModelDevices>[];
      json['devices'].forEach((v) {
        devices!.add(HomeDeviceModelDevices.fromJson(v));
      });
    }
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = {};
    data['type'] = type;
    data['name'] = name;
    if (devices != null) {
      data['devices'] = devices!.map((v) => v.toJson()).toList();
    }
    return data;
  }
}

class HomeDeviceModelDevices {
  int? id;
  String? devId;
  String? name;
  int? model;
  String? type;
  String? gwid;
  String? sModel;
  String? custom;
  String? ip;

  //HomeDeviceModelConfig? config;
  String? firm;
  String? describe;
  String? parentsid;
  String? parentsmodel;
  int? region;
  String? region_name;

  // AllConfig? allConfig;
  // Last? last;
  bool? online;
  double? brightness; // 亮度
  double? colorTemp; // 色温
  bool? hasEvent; // 是否打开
  bool? cardOpen; // 卡片是否展开
  double? tempValue; // 设置温度
  double? currentTempValue; //当前温度
  HomeDeviceModelDevicesLast? last;
  HomeDeviceModelDevicesLastConfig? config;
  DevicesAllConfig? all_config;
  String? power;

  HomeDeviceModelDevices(
      {this.id,
      this.devId,
      this.name,
      this.model,
      this.type,
      this.gwid,
      this.sModel,
      this.custom,
      this.ip,
      this.firm,
      this.describe,
      this.parentsid,
      this.parentsmodel,
      this.region,
      this.online,
      this.currentTempValue,
      this.tempValue,
      this.brightness,
      this.cardOpen = false,
      this.colorTemp,
      this.hasEvent,
      this.region_name,
      this.last,
      this.all_config,
      this.config,
      this.power});

  HomeDeviceModelDevices.fromJson(Map json) {
    id = json['id'];
    devId = json['dev_id'];
    name = json['name'];
    model = json['model'];
    type = json['type'];
    gwid = json['gwid'];
    sModel = json['_model'];
    custom = json['custom'];
    ip = json['ip'];
    // config = json['config'] != null ?  HomeDeviceModelConfig.fromJson(json['config']) : null;
    firm = json['firm'];
    describe = json['describe'];
    parentsid = json['parentsid'];
    parentsmodel = json['parentsmodel'];
    region = json['region'];
    // allConfig = json['all_config'] != null ?  AllConfig.fromJson(json['all_config']) : null;
    last = json['last'] != null
        ? HomeDeviceModelDevicesLast.fromJson(json['last'])
        : HomeDeviceModelDevicesLast();
    online = json['online'];
    region_name = json['region_name'];
    config = json['config'] != null && (json['config'] is Map)
        ? HomeDeviceModelDevicesLastConfig.fromJson(json['config'])
        : HomeDeviceModelDevicesLastConfig();
    all_config = json['all_config'] != null
        ? DevicesAllConfig.fromJson(json['all_config'])
        : DevicesAllConfig();
    power = json['power'] ?? 'off';
    cardOpen = json['cardOpen'] ?? false;
    hasEvent = json['cardOpen'] ?? false;
    brightness = json['brightness'] ?? 0.0;
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = {};
    data['id'] = id;
    data['dev_id'] = devId;
    data['name'] = name;
    data['model'] = model;
    data['type'] = type;
    data['gwid'] = gwid;
    data['_model'] = sModel;
    data['custom'] = custom;
    data['ip'] = ip;
    // if (this.config != null) {
    //   data['config'] = this.config!.toJson();
    // }
    data['firm'] = firm;
    data['describe'] = describe;
    data['parentsid'] = parentsid;
    data['parentsmodel'] = parentsmodel;
    data['region'] = region;
    data['cardOpen'] = cardOpen;
    data['region_name'] = region_name;
    // if (this.allConfig != null) {
    //   data['all_config'] = this.allConfig!.toJson();
    // }
    if (last != null) {
      data['last'] = last!.toJson();
    }
    data['hasEvent'] = hasEvent;
    data['online'] = online;
    data['brightness'] = brightness;
    return data;
  }
}

class HomeDeviceModelDevicesLast {
  num? light_bright = 0.0;
  num? light_color;
  num? light_ct;
  String? power;
  bool? online = false; //是否可用
  String? name;
  HomeDeviceModelDevicesLastConfig? config;
  DevicesAllConfig? all_config;

  HomeDeviceModelDevicesLast(
      {this.light_bright,
      this.light_color,
      this.light_ct,
      this.online,
      this.name,
      this.config,
      this.all_config});

  HomeDeviceModelDevicesLast.fromJson(Map<String, dynamic> json) {
    light_bright = json['light_bright'] ?? 0.0;
    light_color = json['light_color'];
    light_ct = json['light_ct'];
    online = json['online'] ?? false;
    power = json['power'];
    name = json['name'];
    config = json['config'] != null
        ? HomeDeviceModelDevicesLastConfig.fromJson(json['config'])
        : HomeDeviceModelDevicesLastConfig();
    all_config = json['all_config'] != null
        ? DevicesAllConfig.fromJson(json['all_config'])
        : DevicesAllConfig();
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = {};
    data['light_bright'] = light_bright;
    data['light_color'] = light_color;
    data['light_ct'] = light_ct;
    data['online'] = online;
    data['power'] = power;
    data['name'] = name;
    return data;
  }
}

class HomeDeviceModelDevicesLastConfig {
  bool? can_update = false;
  String? type;

  HomeDeviceModelDevicesLastConfig({this.can_update, this.type = ''});

  HomeDeviceModelDevicesLastConfig.fromJson(Map json) {
    can_update = json['can_update'] ?? false;
    type = json['type'] ?? '';
  }
}

class DevicesAllConfig {
  DevicesAllConfigCategory? category;
  List? meanProperties;
  List<String>? enumProperties;
  List<String>? historyProperties;
  List<String>? writeProperties;
  List<String>? readProperties;
  DevicesAllConfigProperties? properties;

  DevicesAllConfig(
      {this.category,
      this.meanProperties,
      this.enumProperties,
      this.historyProperties,
      this.writeProperties,
      this.readProperties,
      this.properties});

  DevicesAllConfig.fromJson(Map<String, dynamic> json) {
    category = json['category'] != null
        ? DevicesAllConfigCategory.fromJson(json['category'])
        : null;
    if (json['mean_properties'] != null) {
      meanProperties = [];
      // json['mean_properties'].forEach((v) { meanProperties!.add( Null.fromJson(v)); });
    }
    enumProperties = json['enum_properties'] != null
        ? json['enum_properties'].cast<String>()
        : [];
    historyProperties = json['history_properties'] != null
        ? json['history_properties'].cast<String>()
        : [];
    writeProperties = json['write_properties'] != null
        ? json['write_properties'].cast<String>()
        : [];
    readProperties = json['read_properties'] != null
        ? json['read_properties'].cast<String>()
        : [];
    properties = json['properties'] != null
        ? DevicesAllConfigProperties.fromJson(json['properties'])
        : null;
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = {};
    if (category != null) {
      data['category'] = category!.toJson();
    }
    if (meanProperties != null) {
      data['mean_properties'] = meanProperties!.map((v) => v.toJson()).toList();
    }
    data['enum_properties'] = enumProperties;
    data['history_properties'] = historyProperties;
    data['write_properties'] = writeProperties;
    data['read_properties'] = readProperties;
    if (properties != null) {
      data['properties'] = properties!.toJson();
    }
    return data;
  }
}

class DevicesAllConfigCategory {
  String? type;
  String? name;

  DevicesAllConfigCategory({this.type, this.name});

  DevicesAllConfigCategory.fromJson(Map<String, dynamic> json) {
    type = json['type'];
    name = json['name'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = {};
    data['type'] = this.type;
    data['name'] = this.name;
    return data;
  }
}

class DevicesAllConfigProperties {
  DevicesAllConfigPropertiesPower? power;
  DevicesAllConfigPropertiesLightBright? lightBright;
  DevicesAllConfigPropertiesLightCt? lightCt;
  DevicesAllConfigPropertiesLightBrightUp? lightBrightUp;
  DevicesAllConfigPropertiesLightBrightUp? lightBrightDown;
  DevicesAllConfigPropertiesLightBrightUp? lightCtUp;
  DevicesAllConfigPropertiesLightBrightUp? lightCtDown;
  DevicesAllConfigPropertiesLightColor? lightColor;

  DevicesAllConfigProperties(
      {this.power,
      this.lightBright,
      this.lightCt,
      this.lightBrightUp,
      this.lightBrightDown,
      this.lightCtUp,
      this.lightCtDown,
      this.lightColor});

  DevicesAllConfigProperties.fromJson(Map<String, dynamic> json) {
    power = json['power'] != null
        ? DevicesAllConfigPropertiesPower.fromJson(json['power'])
        : null;
    lightBright = json['light_bright'] != null
        ? DevicesAllConfigPropertiesLightBright.fromJson(json['light_bright'])
        : null;
    lightCt = json['light_ct'] != null
        ? DevicesAllConfigPropertiesLightCt.fromJson(json['light_ct'])
        : null;
    lightBrightUp = json['light_bright_up'] != null
        ? DevicesAllConfigPropertiesLightBrightUp.fromJson(
            json['light_bright_up'])
        : null;
    lightBrightDown = json['light_bright_down'] != null
        ? DevicesAllConfigPropertiesLightBrightUp.fromJson(
            json['light_bright_down'])
        : null;
    lightCtUp = json['light_ct_up'] != null
        ? DevicesAllConfigPropertiesLightBrightUp.fromJson(json['light_ct_up'])
        : null;
    lightCtDown = json['light_ct_down'] != null
        ? DevicesAllConfigPropertiesLightBrightUp.fromJson(
            json['light_ct_down'])
        : null;
    lightColor = json['light_color'] != null
        ? DevicesAllConfigPropertiesLightColor.fromJson(json['light_color'])
        : null;
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = {};
    if (power != null) {
      data['power'] = power!.toJson();
    }
    if (lightBright != null) {
      data['light_bright'] = lightBright!.toJson();
    }
    if (lightCt != null) {
      data['light_ct'] = lightCt!.toJson();
    }
    if (lightBrightUp != null) {
      data['light_bright_up'] = lightBrightUp!.toJson();
    }
    if (lightBrightDown != null) {
      data['light_bright_down'] = lightBrightDown!.toJson();
    }
    if (lightCtUp != null) {
      data['light_ct_up'] = lightCtUp!.toJson();
    }
    if (lightCtDown != null) {
      data['light_ct_down'] = lightCtDown!.toJson();
    }
    if (lightColor != null) {
      data['light_color'] = lightColor!.toJson();
    }
    return data;
  }
}

class DevicesAllConfigPropertiesPower {
  String? name;
  String? type;
  String? storeType;
  String? rw;
  bool? history;
  String? frontCom;
  List<DevicesAllConfigPropertiesPowerEnum>? enumList;

  DevicesAllConfigPropertiesPower(
      {this.name,
      this.type,
      this.storeType,
      this.rw,
      this.history,
      this.frontCom,
      this.enumList});

  DevicesAllConfigPropertiesPower.fromJson(Map<String, dynamic> json) {
    name = json['name'];
    type = json['type'];
    storeType = json['store_type'];
    rw = json['rw'];
    history = json['history'];
    frontCom = json['front_com'];
    if (json['enum'] != null) {
      enumList = <DevicesAllConfigPropertiesPowerEnum>[];
      json['enum'].forEach((v) {
        enumList!.add(DevicesAllConfigPropertiesPowerEnum.fromJson(v));
      });
    }
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = {};
    data['name'] = name;
    data['type'] = type;
    data['store_type'] = storeType;
    data['rw'] = rw;
    data['history'] = history;
    data['front_com'] = frontCom;
    if (enumList != null) {
      data['enum'] = enumList!.map((v) => v.toJson()).toList();
    }
    return data;
  }
}

class DevicesAllConfigPropertiesPowerEnum {
  String? name;
  String? value;
  String? rw;

  DevicesAllConfigPropertiesPowerEnum({this.name, this.value, this.rw});

  DevicesAllConfigPropertiesPowerEnum.fromJson(Map<String, dynamic> json) {
    name = json['name'];
    value = json['value'];
    rw = json['rw'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = {};
    data['name'] = name;
    data['value'] = value;
    data['rw'] = rw;
    return data;
  }
}

class DevicesAllConfigPropertiesLightBright {
  String? name;
  String? unit;
  int? precision;
  String? storeType;
  String? frontCom;
  DevicesAllConfigPropertiesLightBrightRange? range;

  DevicesAllConfigPropertiesLightBright(
      {this.name,
      this.unit,
      this.precision,
      this.storeType,
      this.frontCom,
      this.range});

  DevicesAllConfigPropertiesLightBright.fromJson(Map<String, dynamic> json) {
    name = json['name'];
    unit = json['unit'];
    precision = json['precision'];
    storeType = json['store_type'];
    frontCom = json['front_com'];
    range = json['range'] != null
        ? DevicesAllConfigPropertiesLightBrightRange.fromJson(json['range'])
        : null;
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = {};
    data['name'] = name;
    data['unit'] = unit;
    data['precision'] = precision;
    data['store_type'] = storeType;
    data['front_com'] = frontCom;
    if (range != null) {
      data['range'] = range!.toJson();
    }
    return data;
  }
}

class DevicesAllConfigPropertiesLightBrightRange {
  int? min;
  int? max;
  int? step;

  DevicesAllConfigPropertiesLightBrightRange({this.min, this.max, this.step});

  DevicesAllConfigPropertiesLightBrightRange.fromJson(
      Map<String, dynamic> json) {
    min = json['min'];
    max = json['max'];
    step = json['step'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = {};
    data['min'] = min;
    data['max'] = max;
    data['step'] = step;
    return data;
  }
}

class DevicesAllConfigPropertiesLightCt {
  String? name;
  String? unit;
  String? type;
  String? storeType;
  String? frontCom;
  DevicesAllConfigPropertiesLightBrightRange? range;

  DevicesAllConfigPropertiesLightCt(
      {this.name,
      this.unit,
      this.type,
      this.storeType,
      this.frontCom,
      this.range});

  DevicesAllConfigPropertiesLightCt.fromJson(Map<String, dynamic> json) {
    name = json['name'];
    unit = json['unit'];
    type = json['type'];
    storeType = json['store_type'];
    frontCom = json['front_com'];
    range = json['range'] != null
        ? DevicesAllConfigPropertiesLightBrightRange.fromJson(json['range'])
        : null;
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = {};
    data['name'] = name;
    data['unit'] = unit;
    data['type'] = type;
    data['store_type'] = storeType;
    data['front_com'] = frontCom;
    if (range != null) {
      data['range'] = range!.toJson();
    }
    return data;
  }
}

class DevicesAllConfigPropertiesLightBrightUp {
  String? name;
  String? type;
  String? storeType;
  String? rw;
  bool? disableScene;

  DevicesAllConfigPropertiesLightBrightUp(
      {this.name, this.type, this.storeType, this.rw, this.disableScene});

  DevicesAllConfigPropertiesLightBrightUp.fromJson(Map<String, dynamic> json) {
    name = json['name'];
    type = json['type'];
    storeType = json['store_type'];
    rw = json['rw'];
    disableScene = json['disable_scene'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = {};
    data['name'] = name;
    data['type'] = type;
    data['store_type'] = storeType;
    data['rw'] = rw;
    data['disable_scene'] = disableScene;
    return data;
  }
}

class DevicesAllConfigPropertiesLightColor {
  String? name;
  String? type;
  String? storeType;
  String? valueType;
  String? frontCom;

  DevicesAllConfigPropertiesLightColor(
      {this.name, this.type, this.storeType, this.valueType, this.frontCom});

  DevicesAllConfigPropertiesLightColor.fromJson(Map<String, dynamic> json) {
    name = json['name'];
    type = json['type'];
    storeType = json['store_type'];
    valueType = json['value_type'];
    frontCom = json['front_com'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = {};
    data['name'] = name;
    data['type'] = type;
    data['store_type'] = storeType;
    data['value_type'] = valueType;
    data['front_com'] = frontCom;
    return data;
  }
}
